/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package stealth;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import resources.properties.Scores;

/**
 *
 * @author Joshua
 */
public class GameManager {

    public static int currentScore = 0;

    
    public static void handleGameEnd(){
        Scores s = Scores.getScores();
        for(int i = 1; i < 10; i++){
            if(Integer.parseInt((String)s.get("score" + i)) <= currentScore){
                for(int j = 9; j != i; j--){
                    s.put("score"+j, s.get("score" + (j-1)));
                    s.put("name"+j, s.get("name" + (j-1)));
                }
                s.put("score"+i, currentScore);
                s.put("name"+1, s.name);
            }
        }
        try {
            URL url = Scores.class.getResource("score_props.properties");
            s.store(new FileWriter(url.getPath()), "");
        } catch (IOException ex) {
            System.err.println("Could not save scores :(");
        }
    }
}
